// 该文件主要用于：创建并暴露一个store实例
import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'

Vue.use(Vuex)

export default new Vuex.Store({
  actions:{
    jijia({state,commit},value){
      if(state.sum % 2){
        commit('JIA',value)
      }
    },
    dengjia({commit},value){
      setTimeout(() => {
        commit('JIA',value)
      }, 1000);
    },
    fuwujia({commit}){
      axios.get('https://api.uomg.com/api/rand.qinghua?format=json').then(
        response => {
          console.log(response.data.content)
          commit('JIA',response.data.content.length)
        },
        error => {
          alert(error.message)
        }
      )
    }

  },
  mutations:{
    JIA(state,value){
      state.sum += value
    },
    JIAN(state,value){
      state.sum -= value
    }
  },
  // 配置state的初始值
  state:{
    sum:1
  }
})